package com.qdu.sort;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

//mount递减 cart递增排序
public class SortDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(SortDriver.class);

        job.setPartitionerClass(TwoSort.FirstPartitioner.class);
        job.setGroupingComparatorClass(TwoSort.GroupingComparator.class);

        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);

        job.setMapOutputKeyClass(TwoSort.IntPair.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        //conf.set("fs.defaultFS", "hdfs://songchao/");
        FileInputFormat.setInputPaths(job, new Path("hdfs://songchao:9000/data/mum_baby"));
        FileOutputFormat.setOutputPath(job, new Path("hdfs://songchao:9000/output/sort"));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
